
var app = getApp()

Page({

    data:{
        banner : [],
        tasks : [],
        recommendPageNum : 1,
        pageSize : 20,
        hideBottomLoading : true
    },

    onLoad : function(){
        var that = this;
        this.initScrollHeight();
        app.checkLogin();
        var data = {"currentPage":1,"pageSize":10,"type":"BANNER"};

        //获取顶部BANNER数据
        app.request("view/banner/list", "POST", data, function(res){
            that.setData({
                banner : res.result.content
            });
       });

        that.loadRecommendData();

    },

    onBannerClick : function(event){
        var id = event.currentTarget.dataset.hi;
        wx.navigateTo({
            url: '../scenicespot/scenicespot?id='+id
        })
    },

    onActivityClick : function(event){
        var id = event.currentTarget.dataset.hi;
        wx.navigateTo({
            url: '../activity/activity?id='+id
        })
    },

    initScrollHeight : function() {
        var that = this;
        wx.getSystemInfo({
            success:function(res){
                that.setData({
                    scrollHeight:res.windowHeight
                });
            }
        });
    },

    //获取推荐活动数据列表
    loadRecommendData : function(){
        var that = this;
        this.setData({
            hideBottomLoading : false
        })
        var data = {"currentPage":this.data.recommendPageNum,"pageSize":this.data.pageSize, "type":"RECOMMEND"};
        app.request("view/activity/list", "POST", data, function(res){
            that.setData({
                tasks : that.data.tasks.concat(res.result.content),
                recommendPageNum : that.data.recommendPageNum + 1,
                hideBottomLoading : true
            });
        });
    }
})